package HomeWork;
/*
2、定义功能完成数组的求和。一个功能求偶数和，一个功能求奇数和。一个功能求总和。

数组： int[] arr = {1,2,3,4,5,6,7,8,9};

 */
public class Extra02 {
    public static void main(String[] args) {
        int[] arr =  {1,2,3,4,5,6,7,8,9};

        System.out.println("奇数和为："+getOddSum(arr));
        System.out.println("偶数和为："+getEvenSum(arr));
        System.out.println("总和为："+getSum(arr));
    }

    //求奇数和
    public static int getOddSum(int[] arr){
        int odd = 0;
        for(int i = 0; i < arr.length; i++){
            if(arr[i]%2 != 0){
                odd += arr[i];
            }
        }
        return odd;
    }

    //求偶数和
    public static int getEvenSum(int[] arr){
        int even = 0;
        for(int i = 0; i < arr.length; i++){
            if(arr[i]%2 == 0){
                even += arr[i];
            }
        }
        return even;
    }

    //求总和
    public static int getSum(int[] arr){
        int sum = 0;
        for(int i = 0; i < arr.length; i++){
                sum += arr[i];
        }
        return sum;
    }
}
